import { NBreadcrumb, type BreadcrumbProps } from "naive-ui";
import type { HTMLAttributes } from "vue";
import { getSlotsDom } from "../utils";
import type { BaseComponentType } from "../types";
export type BreadcrumbFactoryConstructorType = {
  props?: BreadcrumbProps;
  attrs?: HTMLAttributes;
  defaultSlot?: BaseComponentType;
};
export class BreadcrumbFactory {
  private attrs: HTMLAttributes = {};
  private props: BreadcrumbProps = {};
  private defaultSlot: BaseComponentType = null;
  constructor(data?: BreadcrumbFactoryConstructorType) {
    if (data?.props) this.setProps(data.props);
    if (data?.attrs) this.setAttrs(data.attrs);
    if (data?.defaultSlot) this.setDefault(data.defaultSlot);
  }

  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }

  setProps(props: BreadcrumbProps) {
    this.props = props;
    return this;
  }

  setDefault(slot: BaseComponentType) {
    this.defaultSlot = slot;
    return this;
  }

  create() {
    return (
      <NBreadcrumb {...this.props} {...this.attrs}>
        {{
          default:
            this.defaultSlot != null
              ? () => getSlotsDom(this.defaultSlot)
              : null,
        }}
      </NBreadcrumb>
    );
  }
}
